﻿<template>
    <div class="login">
        <el-form ref="formRef" :model="form" label-width="80px">
            <el-form-item label="用户名">
                <el-input v-model="form.phoneNo"></el-input>
            </el-form-item>
            <el-form-item label="密码">
                <el-input v-model="form.password"></el-input>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="login">登录测试</el-button>
            </el-form-item>
        </el-form>
    </div>
</template>

<script setup lang="ts">
import { reactive, warn } from 'vue';
import api from '@/apis/base';
import { errorTips, removeStore, setStore, successTips, warningTips } from '@/utils/utils';
import { useUserStore } from '@/stores/user';
import { useRouter } from 'vue-router';

const userStore = useUserStore();
const router = useRouter();

const form = reactive({
    phoneNo: '13890665502',
    password: '12345d',
    areaCode: '65',
    loginSource: 2,
});

const login = () => {
    api.loginByPhone(form).then(res => {
        if (!res || res.code != 1) return;
        const { token, userInfo } = res.data;

        userStore.setUserInfo(userInfo);
        userStore.setToken(token);
        userStore.setAuthList(['home']);
        router.push('/home');
        successTips('登录成功');
    });
};
</script>

<style scoped lang="scss">
.login {
    width: 500px;
    height: 500px;
    margin: 100px auto;
}
</style>
